package com.leoren.run.utils;



import com.leoren.run.log.L;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @Author Leoren
 * @Date 2019/3/2 11:12
 *
 * 配置文件的读取 ==》关于服务器的配置
 */
public class PropertiesUtil {


    private static Properties pros;

    static {
        String fileName = "wheretoplay.properties";
        pros = new Properties();
        try{
            pros.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"));
        }catch (IOException e){
            L.e(("读取文件"+ fileName +"失败\n"));
            e.printStackTrace();
        }
    }

    public static String getProperty(String key){
        String value = pros.getProperty(key.trim());
        if(StringUtils.isNotBlank(value)){
            return value.trim();
        }
        return null;
    }

    public static String getProperty(String key, String defaultValue){
        String value = pros.getProperty(key.trim());
        if(StringUtils.isBlank(value)){
            value = defaultValue;
        }
        return value.trim();
    }



}
